/**
 * 编辑
 */
function editManage(obj, i) {
    console.log(obj.parents('.dataTables_wrapper').length);
    var saveHtm = '<a href="javascript:void(0)" class="iboss-link" onclick="saveManage($(this),' + i + ')">保存</a>';
    obj.parents('.dataTables_wrapper').find('#myTable tbody>tr').eq(i).find('.operability-td input').addClass('input-style').removeAttr('readonly');
    obj.parent().append(saveHtm);
    obj.remove();
}

/**
 * 保存
 */
function saveManage(obj, i) {
    var editHtm = '<a href="javascript:void(0)" class="iboss-link" onclick="editManage($(this),' + i + ')">编辑</a>';
    obj.parents('.dataTables_wrapper').find('#myTable tbody>tr').eq(i).find('.operability-td input').removeClass('input-style').attr('readonly', 'readonly');
    var saveDate = {};
    var rowIndex = obj.parents('.dataTables_wrapper').find('#myTable tbody>tr').eq(i);
    rowIndex.find('td').each(function () {
        var idx = manageTableObj.cell(this).index().column;
        var name = manageTableObj.column(idx).dataSrc();
        var isEdit = $(this).find('.operability-td').length;
        if (isEdit != 0) {
            var value = $(this).find('.operability-td input').val();
            saveDate[name] = value;
        }
    });
    //非空校验
    for (let index in saveDate) {
        if (!saveDate[index]) {
            DGG.Warning('输入框内容不能为空');
            editManage(obj,i);
            return false;
        }
    }
    obj.parent().append(editHtm);
    obj.remove();

    saveDate["warningType"] = $("#warningType").val();
    saveDate["id"] = manageTableObj.rows(rowIndex).data()[0].id;
    DGG.loading();
    $.ajax({
        type: "post",
        url: sysInfo.basePath + "/zs/warning_configure/update_warning_config.do",
        data: saveDate,
        dataType: "json",
        success: function (result) {
            DGG.loading('close');
            if (result.code == 0) {
                DGG.Succeed('保存成功!')
            } else {
                DGG.Errors(result.msg);
            }
        }
    });
}

/**
 * 新增配置
 */
function addConfiguration() {
    syb("#signOrgName");
    var index = dgg.Open({
        title: '新增配置',
        content: $('#addConfigurationWindow'),
        area: '480px',
        success: function () {
            dgg.loading('close')
        },
        yes: function () {
            var signOrgId = $('#signOrgName').val();
            var signOrgName = $("#signOrgName option:selected").text();
            if (!signOrgId) {
                DGG.Warning('亲！请选择事业部');
                return false;
            }
            DGG.Confire('确认执行此操作？', '操作提示', function () {
                DGG.loading();
                $.ajax({
                    type: "post",
                    url: sysInfo.basePath + "/zs/warning_configure/add_warning_config.do",
                    data: {
                        "warningType": $("#warningType").val(),
                        "signOrgId": signOrgId,
                        "signOrgName": signOrgName
                    },
                    dataType: "json",
                    success: function (result) {
                        DGG.loading('close');
                        layer.close(index);
                        if (result.code == 0) {
                            DGG.Succeed('添加配置成功！');
                            $('#myTable').dataTableExtend("reload");
                        } else {
                            DGG.Errors(result.msg);
                        }
                    }
                });
            });
        }
    });
}

/**
 * 搜索
 */
function reloadTable() {
    $('#myTable').dataTableExtend("reload");
}